package it.intecs.pisa.smarcos.activities;

import it.intecs.pisa.smarcos.R;
import it.intecs.pisa.smarcos.base.Lists;
import it.intecs.pisa.smarcos.base.SpeechManager;
import it.intecs.pisa.smarcos.base.XMLParser;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

 
public class HandleNotification extends BaseActivity {
	
	public static final String INTENT_SHOW="it.intecs.pisa.smarcos.activities.HandleNotification.SHOW";
	private static final String TAG = HandleNotification.class.getSimpleName();
		
	private SpeechManager speechManager;
	private XMLParser xmlParser;
	private Vibrator vibrator;
	private String position;
	private String repeat;
	private View view; 
	private ViewGroup baseCenterView;
	private LayoutInflater inflater;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Log.d(TAG, "OnCreate");

		xmlParser = XMLParser.getInstance(null, null);
		speechManager = SpeechManager.getInstance(getApplicationContext());
		vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
		Intent intent = getIntent();

		// Metodo di BaseViewManager
		Init(getBaseContext());
		inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
		view = inflater.inflate(R.layout.text_view, null);
		setContentView(getBaseView());
		baseCenterView = (ViewGroup) findViewById(R.id.center_base_view);
		baseCenterView.addView(view);
		setD(R.string.NOT_Button_D);
		
		position = getString(R.string.MV_Notification_Voice); 
		repeat = intent.getStringExtra("Notification subject");
		TextView textView = (TextView) findViewById(R.id.TextView);
		textView.setText(repeat);
		textView.setTextSize(24);
		speechManager.say(repeat, false, false);
	}
	
	// CLOSE
	@Override
	public void onClick_A(){
		Log.d(TAG, "onClick_A");
		vibrator.vibrate(100);
		Intent intent;
		intent=new Intent("it.intecs.pisa.smarcos.services.ResultReceiver.SHOW");
		intent.putExtra("Result", "NORESULT");
		intent.addCategory(Intent.CATEGORY_DEFAULT);
		sendBroadcast(intent);
		sentResult = true;
		finish();	
	}
	
	// POSITION
	@Override
	public void onClick_B(){
		Log.d(TAG, "onClick_B");
		vibrator.vibrate(100);
		if(position != null)
			speechManager.say(position, false, false);	
	}
	
	// REPEAT 
	@Override
	public void onClick_C(){
		Log.d(TAG, "onClick_C");
		vibrator.vibrate(100);
		if (repeat != null)		
			speechManager.say(repeat, false, false);
	}

	// DELETE
	@Override
	public void onClick_D(){
		Log.d(TAG, "onClick_D");
		
		xmlParser.deleteElement();
		onClick_A();
	}
}
